SynchronizedPairSet

Ecng.Collections

Represents a thread-safe collection that maintains key/value pairs and allows bidirectional lookups.

継承元: SynchronizedKeyedCollection<T, T>

コンストラクター

SynchronizedPairSet
public SynchronizedPairSet(IEqualityComparer<TKey> comparer)
synchronizedPairSet = SynchronizedPairSet(comparer)

Initializes a new instance of the SynchronizedPairSet class with a specified comparer for keys.

comparer
An equality comparer for keys.
SynchronizedPairSet
public SynchronizedPairSet(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
synchronizedPairSet = SynchronizedPairSet(keyComparer, valueComparer)

Initializes a new instance of the SynchronizedPairSet class with specified comparers for keys and values.

keyComparer
An equality comparer for keys.
valueComparer
An equality comparer for values.
SynchronizedPairSet
public SynchronizedPairSet()
synchronizedPairSet = SynchronizedPairSet()

Initializes a new instance of the SynchronizedPairSet class.

プロパティ

Item
public TKey Item { get; }
value = synchronizedPairSet.Item

Gets the key associated with the specified value.

value
The value for which to retrieve the key.

戻り値: The key corresponding to the specified value.

メソッド

Add
public override void Add(TKey key, TValue value)
synchronizedPairSet.Add(key, value)

Adds the specified key and value to the collection.

key
The key to insert.
value
The value to insert.
CanAdd
protected override bool CanAdd(TKey key, TValue value)
result = synchronizedPairSet.CanAdd(key, value)

Determines whether a key/value pair can be added based on whether the value is already present.

key
The key to be added.
value
The value to be added.

戻り値: true if the value is not already contained; otherwise false.

ContainsValue
public bool ContainsValue(TValue value)
result = synchronizedPairSet.ContainsValue(value)

Determines whether the collection contains an entry with the specified value.

value
The value to locate.

戻り値: true if the value is found; otherwise false.

GetKey
public TKey GetKey(TValue value)
result = synchronizedPairSet.GetKey(value)

Retrieves the key associated with the specified value.

value
The value whose key is requested.

戻り値: The key associated with the given value.

GetValue
public TValue GetValue(TKey key)
result = synchronizedPairSet.GetValue(key)

Retrieves the value associated with the specified key.

key
The key whose value is requested.

戻り値: The value associated with the given key.

OnAdding
protected override void OnAdding(TKey key, TValue value)
synchronizedPairSet.OnAdding(key, value)

Called when an item is being added. Adds the value/key mapping to the internal dictionary.

key
The key being added.
value
The value being added.
OnClearing
protected override void OnClearing()
synchronizedPairSet.OnClearing()

Called when the collection is being cleared. Clears the internal dictionary.

OnRemoving
protected override void OnRemoving(TKey key, TValue value)
synchronizedPairSet.OnRemoving(key, value)

Called when an item is being removed. Removes the value/key mapping from the internal dictionary.

key
The key being removed.
value
The value being removed.
OnSetting
protected override void OnSetting(TKey key, TValue value)
synchronizedPairSet.OnSetting(key, value)

Called when an existing item is being set. Updates the value/key mapping in the internal dictionary. Maintains bijective property by swapping values when a collision occurs.

key
The key being set.
value
The value being set.
RemoveByValue
public bool RemoveByValue(TValue value)
result = synchronizedPairSet.RemoveByValue(value)

Removes the element with the specified value if it is found.

value
The value to remove.

戻り値: true if the item was removed; otherwise false.

SetKey
public void SetKey(TValue value, TKey key)
synchronizedPairSet.SetKey(value, key)

Sets a new key for an existing value, replacing any previous association.

value
The value to associate with the new key.
key
The new key to associate with the value.
SetValue
public void SetValue(TKey key, TValue value)
synchronizedPairSet.SetValue(key, value)

Updates the value associated with a key.

key
The key to update.
value
The new value.
TryAdd
public bool TryAdd(TKey key, TValue value)
result = synchronizedPairSet.TryAdd(key, value)

Attempts to add a new key/value pair if neither key nor value is already present.

key
The key to add.
value
The value to add.

戻り値: true if the pair was added; otherwise false.

TryGetKey
public TKey TryGetKey(TValue value)
result = synchronizedPairSet.TryGetKey(value)

Attempts to get a key for the specified value.

value
The value whose key is requested.

戻り値: The key if found; otherwise the default.

TryGetKey
public bool TryGetKey(TValue value, TKey key)
result = synchronizedPairSet.TryGetKey(value, key)

Attempts to get a key for the specified value, returning a boolean indicating success.

value
The value whose key is requested.
key
When this method returns, contains the key if found.

戻り値: true if the key was found; otherwise false.

TryGetKeyAndRemove
public bool TryGetKeyAndRemove(TValue value, TKey key)
result = synchronizedPairSet.TryGetKeyAndRemove(value, key)

Attempts to get and remove the key associated with the specified value.

value
The value for which to retrieve and remove the key.
key
When this method returns, contains the removed key if found.

戻り値: true if the key was removed successfully; otherwise false.